package com.button.boot.redis.lettuce.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.button.boot.redis.lettuce.model.UserModel;
import com.button.boot.redis.lettuce.service.RedisManager;

@RestController
public class UserController {

    @Autowired
    private RedisManager redisManager;

    @GetMapping("/getValue")
    public String getValue() {
        redisManager.setValue("123", "test");
        return redisManager.getValue("123");
    }

    @GetMapping("/getUser")
    public UserModel getUser() {
        UserModel user = new UserModel();
        user.setName("张三");
        user.setAge(24);
        redisManager.leftPush("user", user);
        return redisManager.leftPop("user");
    }
    
    @GetMapping("/getUserValue")
    @Cacheable(value="userKey")   //将结果缓存,下一次重复请求时会直接返回结果
    public String getUserValue(String key) {
        return redisManager.getValue(key);
    }
}
